import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
  OneToMany,
} from 'typeorm';
import { ApiProperty } from '@nestjs/swagger';
import { Betting } from './betting.entity';

/**
 * 比赛实体
 */
@Entity({ name: 'matches', comment: '比赛表' })
export class Match {
  @ApiProperty({ description: '比赛ID' })
  @PrimaryGeneratedColumn({ comment: '比赛ID' })
  id: number;



  @ApiProperty({ description: '开赛时间' })
  @Column({ 
    name: 'match_time',
    type: 'datetime',
    comment: '开赛时间' 
  })
  matchTime: Date;

  @ApiProperty({ description: '赛事名称' })
  @Column({ 
    name: 'league_name',
    length: 100,
    comment: '赛事名称' 
  })
  leagueName: string;

  @ApiProperty({ description: '主队名称' })
  @Column({ 
    name: 'home_team',
    length: 100,
    comment: '主队名称' 
  })
  homeTeam: string;

  @ApiProperty({ description: '客队名称' })
  @Column({ 
    name: 'away_team',
    length: 100,
    comment: '客队名称' 
  })
  awayTeam: string;

  @ApiProperty({ description: '主队队标URL' })
  @Column({ 
    name: 'home_team_logo',
    length: 255,
    nullable: true,
    comment: '主队队标URL' 
  })
  homeTeamLogo: string;

  @ApiProperty({ description: '客队队标URL' })
  @Column({ 
    name: 'away_team_logo',
    length: 255,
    nullable: true,
    comment: '客队队标URL' 
  })
  awayTeamLogo: string;

  @ApiProperty({ description: '外部ID' })
  @Column({ 
    name: 'external_id',
    length: 50,
    nullable: true,
    comment: '外部系统ID' 
  })
  externalId: string;

  @ApiProperty({ 
    description: '胆推荐状态',
    example: 'none',
    enum: ['none', 'recommend_bold', 'recommend_stable']
  })
  @Column({ 
    name: 'bold_recommendation',
    length: 20,
    default: 'none',
    comment: '胆推荐状态：none-无，recommend_bold-推荐胆，recommend_stable-推荐稳胆' 
  })
  boldRecommendation: string;

  @ApiProperty({ description: '主队胜率' })
  @Column({ 
    name: 'home_win_rate',
    type: 'decimal',
    precision: 5,
    scale: 2,
    nullable: true,
    comment: '主队胜率' 
  })
  homeWinRate: number;

  @ApiProperty({ description: '客队胜率' })
  @Column({ 
    name: 'away_win_rate',
    type: 'decimal',
    precision: 5,
    scale: 2,
    nullable: true,
    comment: '客队胜率' 
  })
  awayWinRate: number;

  @ApiProperty({ description: '备注' })
  @Column({ 
    name: 'remarks',
    type: 'text',
    nullable: true,
    comment: '备注信息' 
  })
  remarks?: string;

  @ApiProperty({ description: '创建时间' })
  @CreateDateColumn({ 
    name: 'created_at',
    comment: '创建时间' 
  })
  createdAt: Date;

  @ApiProperty({ description: '更新时间' })
  @UpdateDateColumn({ 
    name: 'updated_at',
    comment: '更新时间' 
  })
  updatedAt: Date;

  @ApiProperty({ description: '投注选项', type: () => [Betting] })
  @OneToMany(() => Betting, betting => betting.match)
  bettings: Betting[];
}